package com.onesports.intelligent.k12.polarlight.service.student;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.onesports.framework.kit.common.util.ParamUtils;
import com.onesports.intelligent.k12.polarlight.domain.entity.course.ClassStudent;
import com.onesports.intelligent.k12.polarlight.domain.vo.course.ClassStuScheduleDetailVO;
import com.onesports.intelligent.k12.polarlight.mapper.course.ClassStudentMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 班级学生服务
 *
 * @author clw
 * @date 2022-07-15 16:34:32
 */
@Service
@RequiredArgsConstructor
public class ClassStudentService extends ServiceImpl<ClassStudentMapper, ClassStudent> {

    private final ClassStudentMapper classStudentMapper;

    public List<ClassStudent> currentStu(String classId, List<String> stuIds) {
        return this.list(new LambdaQueryWrapper<ClassStudent>()
                .eq(ClassStudent::getClassInfoId, classId)
                .eq(ClassStudent::getActive, true)
                .in(ParamUtils.isNotEmpty(stuIds), ClassStudent::getStudentId, stuIds));
    }

    public List<ClassStudent> currentStu(String classId) {
        return this.list(new LambdaQueryWrapper<ClassStudent>()
                .eq(ClassStudent::getClassInfoId, classId)
                .eq(ClassStudent::getActive, true));
    }


    /**
     * 批量退出学生
     *
     * @param classId
     * @param studentIds
     * @return
     */
    public Boolean exitStudent(String classId, List<String> studentIds) {
        List<ClassStudent> classStudent = list(new LambdaQueryWrapper<ClassStudent>()
                .eq(ClassStudent::getClassInfoId, classId)
                .in(ClassStudent::getStudentId, studentIds));
        classStudent.forEach(i -> {
            i.setExitTime(new Date());
            i.setActive(false);
        });
        return updateBatchById(classStudent);
    }

    public List<ClassStuScheduleDetailVO> stuScheduleDetail(List<String> classIdList, Date currentDate, Date currentTime) {
        return this.classStudentMapper.stuScheduleDetail(classIdList,currentDate,currentTime);
    }
}
